import 'package:abc/model/post_model.dart';
import 'package:abc/view/pagination_list_view.dart';
import 'package:get/get.dart';

// lib/controllers/my_posts_controller.dart

import 'package:get/get.dart';
import 'package:flutter/material.dart';

class MyPostsController extends GetxController with GetSingleTickerProviderStateMixin {
  
  // --- TabBar 控制器 ---
  late TabController tabController;
  final List<String> tabs = ['已发布', '待审核', '审核失败'];
  
  // --- 响应式状态 ---
  final earningsInfo = EarningsInfo(
    currentEarnings: 7306,
    totalEarnings: 7306,
    detailsButtonText: '收益明细',
  ).obs;

  final publishedList = <Post>[].obs;
  final pendingList = <Post>[].obs;
  final failedList = <Post>[].obs;

  @override
  void onInit() {
    super.onInit();
    tabController = TabController(length: tabs.length, vsync: this);
    
    // 模拟数据加载
    _loadMockPosts();
  }

  @override
  void onClose() {
    tabController.dispose();
    super.onClose();
  }

  // ============== 模拟帖子数据 ==============
  void _loadMockPosts() {
    // 模拟已发布数据 (来自图片)
    publishedList.assignAll([
      // 帖子 1: 无图片
    Post(
      avatarUrl: 'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
      username: '空大菜菜',
      time: '9小时前',
      title: '今日三餐',
      content: '今天尝试了一下新的菜式，全家都说好吃！特别推荐给大家...',
      imageUrls: [],
      tags: ['日常', '美食'],
      likes: 852, comments: 125,watch: 100, shares: 36, isFollowed: true,
      status: 0
    ),
    // 帖子 2: 三张图片
    Post(
      avatarUrl: 'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
      username: '天空蔚蓝',
      time: '2小时前',
      title: '今日午餐',
      content: '美食美景，人生一大享受！',
      imageUrls: [
        'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
        'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
        'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
      ],
      tags: ['日常', '美食'],
      likes: 980, comments: 345,watch: 130, shares: 120, isFollowed: false,
      status: 0
    ),
    
    ]);

    // 模拟待审核数据
    pendingList.assignAll([
    // 帖子 3: 两张图片
    Post(
      avatarUrl: 'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
      username: '小美酱',
      time: '刚刚',
      title: '今日穿搭',
      content: '新的裙子，新的心情~',
      imageUrls: [
        'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
        'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
       
      ],
      tags: ['日常', '美食'],
      likes: 1200, comments: 450,watch: 3550, shares: 200, isFollowed: false,
      status: 1
    ),
    // 帖子 4: 1张图片
    Post(
      avatarUrl: 'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
      username: '广告推广',
      time: '推广',
      title: '汽车广告',
      content: '', // 广告内容通常在图片中
      imageUrls: ['https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893'], // 模拟横幅广告图
      tags: ['日常', '美食'],
      likes: 0, comments: 0,watch: 10, shares: 0, isFollowed: true,
      status: 1
    ),
   
    ]);

       // 模拟审核失败数据
    failedList.assignAll([
    // 帖子 3: 两张图片
    Post(
      avatarUrl: 'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
      username: '小美酱',
      time: '刚刚',
      title: '今日穿搭',
      content: '新的裙子，新的心情~',
      imageUrls: [
        'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
        'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
       
      ],
      tags: ['日常', '美食'],
      likes: 1200, comments: 450,watch: 3550, shares: 200, isFollowed: false,
      status: 2
    ),
    // 帖子 4: 1张图片
    Post(
      avatarUrl: 'https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893',
      username: '广告推广',
      time: '推广',
      title: '汽车广告',
      content: '', // 广告内容通常在图片中
      imageUrls: ['https://img1.baidu.com/it/u=877618338,2738144752&fm=253&app=138&f=JPEG?w=608&h=893'], // 模拟横幅广告图
      tags: ['日常', '美食'],
      likes: 0, comments: 0,watch: 10, shares: 0, isFollowed: true,
      status: 2
    ),
   
    ]);
  }
}

// 顶部收益信息模型
class EarningsInfo {
  final int currentEarnings;
  final int totalEarnings;
  final String detailsButtonText;

  EarningsInfo({
    required this.currentEarnings,
    required this.totalEarnings,
    required this.detailsButtonText,
  });
}